home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************/
- /* */
- /* Source - DebuggerDA.c */
- /* Author - Alexander S. Colwell, Copyright (C) 1988, 1989 */
- /* */
- /* Purpose - This is the "Debugger" desk accessory to simplify */
- /* debugging code resources, DA's or applications that */
- /* does not have a debugging output window. It requires */
- /* System 4.1 or greater version. */
- /* */
- /* Routine - Main : Main entry point module. */
- /* DoOpen : Open the DA and initialized. */
- /* DoClose : Close the DA and wrap it up. */
- /* DoControl : Process DA control commands. */
- /* DoEvent : Process DA event. */
- /* DoUpdate : Update window. */
- /* DoMouse : Process mouse-down. */
- /* DoActivate : Activate/Deactivate window. */
- /* DoActivateScrollBars: Activate the scroll bars */
- /* DoDeActivateScrollBars:Deactivate the scroll bars. */
- /* DoIdle : Do idle processing. */
- /* DoKey : Process key inputs. */
- /* DoMenu : Do menu commands. */
- /* DoContent : Process mouse down inside window*/
- /* DoCopy : Copy the selected text. */
- /* DoClear : Clear the display. */
- /* DoQuit : Quit the DA, found a problem. */
- /* DoInfo : Show information about this DA. */
- /* DoStartStopOutput : Start/Stop output display. */
- /* DoError : Show error message to user. */
- /* DoTextClick : Do text clicking. */
- /* DoScrollBar : Do scroll bar. */
- /* DoTextScroll : Do text scrolling action. */
- /* DoClickScroll : Do click scrolling. */
- /* DoHighLite : Do highliting. */
- /* DoNewLineToReturn : Convert NEW-LINE to RETURN chars*/
- /* DoPrintLine : Print line. */
- /* DoDbgPrintSetup : Setup debugging print output. */
- /* DoDbgPrint : Do debugging print output. */
- /* DoPrintDump : Dump stuff. */
- /* DoRestoreClippings : Restore text view clippings. */
- /* DoAdjustScrollBar : Adjust the scroll bar's thumb. */
- /* DoSetupView : Setup the view. */
- /* DoAdjustView : Adjust the view. */
- /* DoResizeScrollBar : Resize the scroll bar. */
- /* DoDlgCenter : Center dialog window. */
- /* DoItemIdx : Find item index str comparsion. */
- /* GetResourceID : Get DA resource ID number. */
- /* */
- /* Revisions - None. */
- /* */
- /********************************************************************/
-
- #include "Debugger.h" /* DA Debugger defs */
- #include <Color.h> /* Color Manager defs */
- #include <CType.h> /* C Type defs */
- #include <StdArg.h> /* Standard Argument defs */
- #include <SetUpA4.h> /* Desk Accessory defs */
- #include <PE.h> /* Program Edit defs */
-
- /* Misc definitions */
- #define NIL (0L) /* NIL pointer */
- #define abs(a) (a<0?-a:a) /* Absolute macro function */
- #define min(a,b) (a<b?a:b) /* Minumim macro function */
- #define max(a,b) (a<b?b:a) /* Maximum macro function */
-
- /* Trap definitions */
- #define SysEnvironsTrap 0xa090 /* System Enviorment trap */
- #define UnknownTrap 0xa89f /* Unknown trap instruction */
-
- /* Limit definitions */
- #define maxColumns 132 /* Maximum # of columns */
-
- /* Resource ID #'s */
- #define windID 0 /* Window ID # */
- #define infoID 0 /* Info dialog ID # */
- #define errorID 1 /* Error dialog ID # */
- #define strID 0 /* String STR ID # */
- #define errID 1 /* Error STR ID # */
- #define optionsID 0 /* Options ID # */
- #define debuggerID 0 /* Debugger ID # */
-
- typedef enum { /* Menu commands */
- Info = 1, /* On-line information */
- NullItem2,
- StartOutput, /* Start/Stop output display */
- Quit /* Quit from DA */
- } MENU;
-
- typedef enum { /* String ID #'s */
- itmStartOutput = 1, /* "Start Output" item */
- itmStopOutput, /* "Stop Output" item */
- bufTableOvrFlw, /* Table overflow */
- bufDataOvrFlw, /* Data buffer overflow */
- bufBufOvrFlw /* Buffer size overflow */
- } STRID;
- /* Resource types */
- #define optionType 'Opts' /* Option definitions type */
-
- typedef enum { /* Error messages */
- errFailOpenDA = 1, /* Fail to open DA */
- errNoGlobals, /* Fail to allocate globals */
- errLowMemory, /* Low memory error */
- errOldSystem, /* Old System file < 4.1 version*/
- errLisaClone, /* Lisa clone Macintosh */
- errOriginalMac /* Original 128/512 Mac! */
- } ERROR;
-
- typedef struct { /* Options definitions */
- short maxTextSize; /* Maximum text size */
- short fontFamily; /* Font ID family */
- short fontSize; /* Font size */
- short spacesPerTab; /* # of spaces per tab */
- long bufTableSize; /* Buffer table size */
- long bufDataSize; /* Buffer data size */
- } OPT;
- typedef OPT *OPTPTR;
- typedef OPTPTR *OPTHDL;
-
- short alreadyOpen = FALSE;/* 1 -> DA is already open */
- SysEnvRec sysEnv; /* System enviroment */
- DCtlPtr dce; /* Device control entry */
- WindowPtr wp = NIL; /* My window pointer */
- Rect originalRect; /* Original window rect area */
- PEHandle peHdl = NIL; /* PE handle */
- short active = FALSE; /* Active flag indicator */
- ControlHandle hScrollBar = NIL; /* Horz scroll bar control hdl */
- ControlHandle vScrollBar = NIL; /* Horz scroll bar control hdl */
- DBGHDL dbgHdl = NIL; /* Debugger handle */
- OPTHDL optHdl = NIL; /* Options handle */
- short cursorMode = FALSE; /* Current I-beam cursor mode */
- MenuHandle menu = NIL; /* Menu handle */
- short menuID = 0; /* Menu ID # */
- long **bufTable = NIL; /* Buffer index table handle */
- char **bufData = NIL; /* Buffer data handle */
- short outputEnable = TRUE;/* Output stream enable flag */
-
- char PrintOutputBuf[1024];/* Print output buffer */
-
- pascal void DoTextScroll(); /* Define forwared references */
- pascal void DoClickScroll();
- pascal void DoHighLite();
- void DoPrintChar();
-
- DialogTHndl DoDlgCenter();
-
- main(p,d,n)
-
- cntrlParam *p; /* Parameter block */
- DCtlPtr d; /* Device control entry */
- short n; /* Entry point selector */
-
- {
-
- WindowPtr savePort; /* Save current window port */
- short saveResFile; /* Save current resource file */
-
- if (d->dCtlStorage == 0) { /* Check if got the globals 1st!*/
-
- if (n == 0) { /* Check if requesting "Open" */
-
- DoError(errNoGlobals);/* Opps, fail to get globals */
-
- CloseDriver(d->dCtlRefNum);/* Close the DA */
-
- }
-
- }
-
- else { /* Got the globals then continue*/
-
- RememberA4(); /* Remember A4 register */
-
- GetPort(&savePort); /* Get current window port */
-
- if (wp) /* Check if window ptr valid */
- SetPort(wp); /* Set port to my window */
-
- dce = d; /* Save DCE ptr into our globals*/
-
- dce->dCtlFlags &= ~dCtlEnable;/* Set it not to be re-entrant*/
-
- switch(n) { /* Handle request: */
-
- case 0: /* "Open" */
- DoOpen(); break;
-
- case 2: /* "Control" */
- DoControl(p->csCode,p->csParam); break;
-
- case 4: /* "Close" */
- DoClose(); break;
-
- }
-
- dce->dCtlFlags |= dCtlEnable;/* Enable calls once more */
-
- SetPort(savePort); /* OK, let's restore it */
-
- }
-
- return(0); /* Return default success */
-
- }
-
- DoOpen()
-
- {
-
- short rom; /* Working ROM id */
- short machine; /* Working Mac id */
- Rect wRect; /* Working window rect area */
- register PEPtr pePtr; /* Working edit pointer */
- DBGPTR dbgPtr; /* Working debugger pointer */
- register short canDoIt; /* Working can do it indicator */
- register short errCode = errFailOpenDA;/* Working error code*/
- Point pt; /* Working point */
-
- /* Add neccesary driver flags */
- dce->dCtlFlags |= dNeedLock|dNeedGoodBye;
-
- if (wp) /* Check if there a window */
- if (wp != FrontWindow())/* Check if not in the front */
- SelectWindow(wp); /* Bring our window front */
-
- if (!alreadyOpen) { /* Check if require inits */
-
- Environs(&rom,&machine);/* Get Mac's evniroment */
-
- if (machine == macXLMachine) {/* Check if Lisa clone */
- canDoIt = FALSE; /* It's a Lisa computer! */
- errCode = errLisaClone;/* Set error message */
- }
-
- else if (rom >= 0x0078) /* It's Mac II */
- canDoIt = TRUE; /* It's Mac II computer */
-
- else if (rom >= 0x0076) /* It's Mac SE */
- canDoIt = TRUE; /* It's Mac SE computer */
-
- else if (rom >= 0x0075) {/* it's 128K rom */
-
- /* Check if Mac 512KE computer */
- if (MemTop > (char *)(1024L * 512L))
- canDoIt = TRUE; /* It's Mac 512K Enhanced */
-
- else
- canDoIt = TRUE; /* Its Mac Plus computer */
-
- }
-
- else if (rom >= 0x0069){/* It's 64K rom, it's old one */
- canDoIt = FALSE; /* It's original Mac! */
- errCode = errOriginalMac;/* Set error message */
- }
-
- if (canDoIt) { /* OK, we can do it! */
-
- /* Check if SysEnvirons valid */
- if ((long)NGetTrapAddress(SysEnvironsTrap,OSTrap) !=
- (long)NGetTrapAddress(UnknownTrap,ToolTrap)) {
-
- SysEnvirons(1,&sysEnv);/* Get system enviroment */
-
- /* Check if has latest version */
- if (sysEnv.systemVersion >= 0x0410) {
-
- wp = GetNewWindow(GetResourceID(windID),NIL,-1L);
-
- if (wp) { /* Check if got the window */
-
- ShowWindow(wp);/* OK, let's show it */
-
- SetPort(wp);/* Set port to our window */
-
- /* Set open DA indicator */
- alreadyOpen = TRUE;
-
- /* Save window association */
- ((WindowPeek)wp)->windowKind = dce->dCtlRefNum;
-
- /* Tell device where I am */
- dce->dCtlWindow = wp;
-
- /* Save original rect area */
- originalRect = wp->portRect;
- LocalToGlobal(&originalRect.top);
- LocalToGlobal(&originalRect.bottom);
-
- /* Set horizontal rect area */
- wRect.left = wp->portRect.left - 1;
- wRect.top = wp->portRect.bottom - 15;
- wRect.right = wp->portRect.right - 14;
- wRect.bottom = wp->portRect.bottom + 1;
-
- /* Check if create scroll bar */
- hScrollBar = NewControl(wp,&wRect,"",FALSE,
- 0,0,0,scrollBarProc,0L);
-
- /* Set vertical rect area */
- wRect.left = wp->portRect.right - 15;
- wRect.top = wp->portRect.top - 1;
- wRect.right = wp->portRect.right + 1;
- wRect.bottom = wp->portRect.bottom - 14;
-
- /* Check if create scroll bar */
- vScrollBar = NewControl(wp,&wRect,"",FALSE,
- 0,0,0,scrollBarProc,0L);
-
- /* Get options definitions */
- optHdl = (OPTHDL)(GetResource(optionType,
- GetResourceID(optionsID)));
-
- /* Get debugger definitions */
- dbgHdl = (DBGHDL)(GetResource(debuggerType,
- GetResourceID(debuggerID)));
-
- TextFace(0);/* Set to "Plain" style font*/
-
- if (optHdl) {/* Check if got option hdl*/
- TextSize((*optHdl)->fontSize);
- TextFont((*optHdl)->fontFamily);
- }
-
- else { /* Nope, default to standard */
- TextSize(9);
- TextFont(monaco);
- }
-
- /* Set edit view rect area */
- wRect.left = wp->portRect.left;
- wRect.top = wp->portRect.top + 5;
- wRect.right = wp->portRect.right - 15;
- wRect.bottom = wp->portRect.bottom - 15;
-
- /* Check if get edit handle */
- if (peHdl = PENew(&wRect)) {
-
- pePtr = *peHdl;/* Set edit pointer */
-
- /* Set auto scroll hook */
- pePtr->clikLoop = (ProcPtr)DoClickScroll;
-
- /*Check if has color monitor */
- if (sysEnv.hasColorQD)
- pePtr->highHook = (ProcPtr)DoHighLite;
-
- /* Set horizontal offset */
- pePtr->viewOrgH = -5;
-
- /* Set vertical offset */
- pePtr->viewOrgV = 0;
-
- /* Set the # of spaces per tab */
- (*peHdl)->tabWidth = CharWidth(' ') *
- (*optHdl)->spacesPerTab;
-
- /* Restore text view clippings */
- DoRestoreClippings();
-
- }
-
- /* Check if got the menu handle */
- if (menu = GetMenu(menuID = GetResourceID(menuID))) {
-
- /* Reset the default menu ID # */
- (**menu).menuID = menuID;
-
- /* Init menu ID # */
- dce->dCtlMenu = menuID;
-
- if (!dbgHdl)/* Check if fail to get it*/
- DisableItem(menu,StartOutput);
-
- }
-
- else /* Fail to get menu handle */
- menuID = 0;/* Reset menu ID # */
-
- if (optHdl) {/* Check if got option info*/
-
- /* Allocate buffer table */
- bufTable = (long **)(NewHandle(
- (long)((*optHdl)->bufTableSize) *
- (long)(sizeof(long))));
-
- /* Allocate buffer data */
- bufData = NewHandle(
- (long)((*optHdl)->bufDataSize) *
- (long)(sizeof(char)));
-
- }
- /* Check if memory runing low */
- if (!hScrollBar || !vScrollBar ||
- !peHdl || !menu || !optHdl || !dbgHdl ||
- !bufTable || !bufData)
- DoError(errLowMemory);
-
- /* Check if got the resources */
- if (dbgHdl) {
-
- /* Make sure it correct size */
- SetHandleSize(dbgHdl,
- (long)(sizeof(DBGINTERFACE)));
-
- dbgPtr = *dbgHdl;/* Set debugger ptr*/
-
- /* Init debugger buffer stuff */
- dbgPtr->bufError = dbgNoOvrFlw;
- dbgPtr->bufTableIdx = 0;
- dbgPtr->bufNextIdx = 0;
- dbgPtr->bufDataIdx = 0;
- dbgPtr->bufTableSize = 0L;
- dbgPtr->bufTable = NIL;
- dbgPtr->bufData = NIL;
- dbgPtr->bufDataSize = 0L;
- dbgPtr->daRefNbr = 0;
-
- /* Check if other tables valid */
- if (optHdl && bufTable && bufData) {
- dbgPtr->bufTableSize =
- (*optHdl)->bufTableSize;
- dbgPtr->bufTable = bufTable;
- dbgPtr->bufData = bufData;
- dbgPtr->bufDataSize =
- (*optHdl)->bufDataSize;
- dbgPtr->daRefNbr = dce->dCtlRefNum;
- }
-
- ChangedResource(dbgHdl);/* Update it*/
- WriteResource(dbgHdl);
-
- }
-
- }
-
- }
-
- else /* Require newer system */
- errCode = errOldSystem;
-
- }
-
- else /* Require new system */
- errCode = errOldSystem;
-
- }
-
- if (!wp) { /* Check if fail to open */
-
- DoError(errCode); /* Fail to open DA */
-
- DoQuit(); /* Let's get out now! */
-
- }
-
- }
-
- }
-
- DoClose()
-
- {
-
- register Handle hdl; /* Working handle */
- Rect curRect; /* Working current rect area */
- register Rect **wRect; /* Working window rect area */
-
- if (dbgHdl) { /* Check if have the interface */
-
- (*dbgHdl)->daRefNbr = 0;/* OK, let's clear these */
- (*dbgHdl)->bufTable = NIL;
- (*dbgHdl)->bufData = NIL;
-
- ChangedResource(dbgHdl);/* Update the resource, too */
- WriteResource(dbgHdl);
-
- dbgHdl = NIL; /* Clear the handle, but don't*/
- /* release it since other DA's */
- /* and etc will be using it, too*/
-
- }
-
- if (bufTable) /* Check if it's valid */
- DisposHandle(bufTable); /* Release it to memory manager */
- bufTable = NIL; /* Invalidate it */
-
- if (bufData) /* Check if it's valid */
- DisposHandle(bufData); /* Release it to memory manager */
- bufData = NIL; /* Invalidate it */
-
- if (optHdl) /* Check if have option handle */
- ReleaseResource(optHdl);/* Release it */
- optHdl = NIL; /* Invalidate it too */
-
- if (menu) { /* Check if have the menu handle*/
-
- DeleteMenu(menuID); /* Delete menu from menu bar */
- DrawMenuBar();
-
- DisposeMenu(menu); /* Release menu handle */
-
- menu = NIL; /* Invalidate the menu handle */
-
- dce->dCtlMenu = 0; /* Clear-out menu ID # */
-
- }
-
- if (peHdl) { /* Check if edit handle is valid*/
-
- PEDispose(peHdl); /* Release it now */
-
- peHdl = NIL; /* Invalidate the edit handle */
-
- }
-
- if (wp) { /* Check if window ptr valid */
-
- curRect = wp->portRect; /* Translate to global coordinates*/
- LocalToGlobal(&curRect.top);
- LocalToGlobal(&curRect.bottom);
-
- DisposeWindow(wp); /* Delete the window now */
-
- wp = NIL; /* Reset it now */
-
- /* Check if window has changed */
- if (!EqualRect(&curRect,&originalRect)) {
-
- /* Check if got the window handle*/
- if (wRect = ((Rect **)GetResource('WIND',
- GetResourceID(windID)))) {
-
- **wRect = curRect;/* Save new current location */
-
- ChangedResource(wRect);/* Mark it changed */
-
- WriteResource(wRect);/* Write resource now */
-
- }
-
- }
-
- }
-
- /* Get the 'STR#' resource */
- if (hdl = GetResource('STR#',GetResourceID(strID)))
- ReleaseResource(hdl); /* OK, let's release it now */
- if (hdl = GetResource('STR#',GetResourceID(errID)))
- ReleaseResource(hdl); /* OK, let's release it now */
-
- InitCursor(); /* Restore to arrow cursor */
-
- alreadyOpen = FALSE; /* Reset it (really doesn't matter)*/
-
- }
-
- DoControl(code,parm)
-
- short code; /* Control command code */
- short *parm; /* "csParam" list pointer */
-
- {
-
- switch(code) { /* Handle request: */
-
- case accEvent: /* "Event" */
- DoEvent(*((EventRecord **)parm)); break;
-
- case accMenu: /* "Menu" */
- DoMenu(*(parm + 1)); break;
-
- case accRun: /* "Run" */
- DoIdle(); break;
-
- case accCopy: /* "Copy" */
- DoCopy(); break;
-
- case accClear: /* "Clear" */
- DoClear(); break;
-
- case goodBye: /* "GoodBye" */
- DoClose(); break;
-
- case accDbgPrint: /* "DbgPrint" */
- DoDbgPrint(((long *)(parm))); break;
-
- case accDbgDump: /* "DbgDump" */
- DoPrintDump(*((long *)(parm)),*(((long *)(parm))+1)); break;
-
- }
-
- }
-
- DoEvent(e)
-
- register EventRecord *e; /* Event Record pointer */
-
- {
-
- switch(e->what) { /* Handle request: */
-
- case updateEvt: /* "Update" */
- DoUpdate(); break;
-
- case mouseDown: /* "Mouse Down" */
- DoMouse(e->where,e->modifiers); break;
-
- case activateEvt: /* "Activate" */
- DoActivate((Boolean)(e->modifiers & activeFlag)); break;
-
- case keyDown: /* "Key Down" */
- case autoKey: /* "Auto-Key Down" */
-
- /* Handle the input key */
- DoKey((char)(e->message & charCodeMask),
- (char)((e->message & keyCodeMask) >> 8L),
- e->modifiers);
-
- }
-
- }
-
- DoUpdate()
-
- {
-
- Rect wRect; /* Working rect area */
-
- BeginUpdate(wp); /* Start update processing */
-
- ClipRect(&wp->portRect); /* Reset clipping for drawing */
-
- EraseRect(&wp->portRect); /* Erase part of screen first */
-
- DrawGrowIcon(wp); /* Draw the grow icon */
-
- DrawControls(wp); /* Draw the controls */
-
- if (peHdl) { /* Check if has edit handle */
-
- DoRestoreClippings(); /* Restore text view clippgins */
-
- PEUpdate(peHdl); /* OK, let's update it */
-
- }
-
- EndUpdate(wp); /* Wrapup update processing */
-
- }
-
- DoMouse(p,modifiers)
-
- Point p; /* Mouse point position */
- short modifiers; /* Mouse's modifiers */
-
- {
-
- register long i; /* Working index */
- Rect wRect; /* Working window rect area */
- register long wGrow; /* Working grow size */
- ProcPtr wDef; /* Working window proc hdl */
-
- /* Get window proc definition */
- wDef = (ProcPtr)*((WindowPeek)wp)->windowDefProc;
-
- /* Check if in "Content" */
- if (CallPascalL(8,wp,(int)wHit,p,wDef) == wInContent)
- DoContent(p,modifiers);
-
- /* Check if in "Grow" */
- else if (CallPascalL(8,wp,(int)wHit,p,wDef) == wInGrow) {
-
- SetRect(&wRect,100,100,32767,32767);/* Define the limits*/
-
- wGrow = GrowWindow(wp,p,&wRect);/* OK, let's grow it now*/
-
- if (wGrow) { /* Check if specified new size */
-
- /* Reset new size */
- SizeWindow(wp,LoWord(wGrow),HiWord(wGrow),TRUE);
-
- DoResizeScrollBar();/* Resize the scroll bar */
-
- InvalRect(&wp->portRect);/* Invalidate everything */
-
- DoAdjustScrollBar();/* Adjust scroll bar */
-
- }
-
- }
-
- /* Check if in "Zoom In" */
- else if (CallPascalL(8,wp,(int)wHit,p,wDef) == wInZoomIn) {
-
- ZoomWindow(wp,inZoomIn,TRUE);/* Zoom it in */
-
- DoResizeScrollBar(); /* Resize the scroll bar */
-
- DoAdjustScrollBar(); /* Adjust scroll bar */
-
- }
- /* Check if in "Zoom Out" */
- else if (CallPascalL(8,wp,(int)wHit,p,wDef) == wInZoomOut) {
-
- ZoomWindow(wp,inZoomOut,TRUE);/* Zoom it out */
-
- DoResizeScrollBar(); /* Resize the scroll bar */
-
- DoAdjustScrollBar(); /* Adjust scroll bar */
-
- }
-
- }
-
- DoActivate(activate)
-
- short activate; /* Activate flag indicator */
-
- {
-
- Rect wRect; /* Working window rect area */
-
- /* Set vertical control area */
- wRect.left = wp->portRect.right - 14;
- wRect.top = wp->portRect.top - 1;
- wRect.right = wp->portRect.right + 1;
- wRect.bottom = wp->portRect.bottom - 16;
-
- ClipRect(&wRect); /* Reset clippings for a moment */
-
- if (activate) { /* Check if activating */
-
- dce->dCtlFlags |= dNeedTime;/* Allow periodic invokation*/
-
- dce->dCtlDelay = 15; /* Reset delay timer */
-
- if (peHdl) { /* Check if got the text */
-
- active = TRUE; /* Activate text editing */
-
- PEActivate(peHdl); /* Activate the text */
-
- }
-
- DoActivateScrollBars(); /* Activate scroll bars */
-
- if (menu) { /* Check if menu is valid */
-
- InsertMenu(menu,0); /* Insert it into the menu bar */
- DrawMenuBar();
-
- dce->dCtlMenu = menuID;/* Reset menu ID # */
-
- }
-
- }
-
- else { /* Nope, deactivating */
-
- if (dbgHdl) { /* Check if it's valid */
-
- /* Check if there buffer outputs*/
- if ((*dbgHdl)->bufTableIdx != (*dbgHdl)->bufNextIdx) {
-
- /* Allow periodic invokation */
- dce->dCtlFlags |= dNeedTime;
-
- dce->dCtlDelay = 15;/* Reset delay timer */
-
- }
-
- else /* No, buffer outputs */
- dce->dCtlFlags &= ~dNeedTime;/* Turn off perdiodic runs*/
-
- }
-
- else /* Nope, use default settings */
- dce->dCtlFlags &= ~dNeedTime;/* Turn off perdiodic runs*/
-
- active = FALSE; /* Deactivate text editing */
-
- if (peHdl) /* Check if got the text */
- PEDeactivate(peHdl);/* Deactivate the text */
-
- DoDeActivateScrollBars();/* Deactivate scroll bars */
-
- InitCursor(); /* Restore to arrow cursor */
-
- cursorMode = FALSE; /* Reset cursor mode */
-
- if (menu) { /* Check if menu is valid */
-
- DeleteMenu(menuID); /* Delete it from the menu bar */
- DrawMenuBar();
-
- dce->dCtlMenu = 0; /* Clear-out menu ID # */
-
- }
-
- }
-
- }
-
- DoActivateScrollBars()
-
- {
-
- Rect wRect; /* Working rect area */
-
- ClipRect(&wp->portRect); /* Set clippings for moment */
-
- if (hScrollBar) /* Check if have horz scroll bar*/
- ShowControl(hScrollBar);/* Show the scroll bar */
-
- if (vScrollBar) /* Check if have vert scroll bar*/
- ShowControl(vScrollBar);/* Show the scroll bar */
-
- /* Invalidate drag icon */
- wRect.top = wp->portRect.bottom - 14;
- wRect.bottom = wp->portRect.bottom;
- wRect.left = wp->portRect.right - 14;
- wRect.right = wp->portRect.right;
- InvalRect(&wRect);
-
- DoRestoreClippings(); /* Restore clippings */
-
- }
-
- DoDeActivateScrollBars()
-
- {
-
- Rect wRect; /* Working rect area */
-
- ClipRect(&wp->portRect); /* Set clippings for moment */
-
- if (hScrollBar) /* Check if have horz scroll bar*/
- HideControl(hScrollBar);/* Hide the scroll bar */
-
- if (vScrollBar) /* Check if have vert scroll bar*/
- HideControl(vScrollBar);/* Hide the scroll bar */
-
- /* Clear drag icon */
- wRect.top = wp->portRect.bottom - 14;
- wRect.bottom = wp->portRect.bottom;
- wRect.left = wp->portRect.right - 14;
- wRect.right = wp->portRect.right;
- EraseRect(&wRect);
-
- DoUpdate(); /* Update the DA window */
-
- DoRestoreClippings(); /* Restore clippings */
-
- }
-
- DoIdle()
-
- {
-
- register short id; /* Working string ID # */
- register DBGPTR dbgPtr; /* Working debugger pointer */
- register char *s,*f; /* Working string pointers */
- Str255 wStr; /* Working string */
- Point p; /* Working mouse location */
-
- if (active) { /* Check if it's activated */
-
- GetMouse(&p); /* Get mouse location */
-
- if (peHdl) { /* Check if got the text */
-
- PEIdle(peHdl); /* Do cursor blinking stuff */
-
- /* Check if within view */
- if (PtInRect(p,&(*peHdl)->viewRect)){
-
- if (!cursorMode) {/* Check if not showing I-beam*/
-
- /* Reset to I-Beam cursor */
- SetCursor(*GetCursor(iBeamCursor));
-
- cursorMode = TRUE;/* Reset cursor mode */
- }
-
- }
-
- else { /* Reset to standard arrow cursor*/
-
- if (cursorMode) {/* Check if using I-Beam cursor*/
-
- InitCursor();/* Restore to arrow cursor */
-
- cursorMode = FALSE;/* Reset cursor mode */
-
- }
-
- }
-
- }
-
- }
-
- if (dbgHdl) { /* Check if debugger handle valid*/
-
- if ((*dbgHdl)->bufError) {/* Check for buffer overflow */
-
- /* Get buffer error ID # */
- switch((*dbgHdl)->bufError) {
- case bufTableOvrFlw:
- id = dbgTableOvrFlw; break;
-
- case bufDataOvrFlw:
- id = dbgDataOvrFlw; break;
-
- case bufBufOvrFlw:
- id = dbgBufOvrFlw;
-
- }
- /* Let user know about it */
- GetIndString(wStr,GetResourceID(strID),id);
- DoPrintLine("%p\n",wStr);
-
- /* Reset flag indicator */
- (*dbgHdl)->bufError = dbgNoOvrFlw;
-
- }
-
- dbgPtr = *dbgHdl; /* Set debugger pointer */
-
- /* Check if has changed */
- if (dbgPtr->bufTableIdx != dbgPtr->bufNextIdx) {
-
- /* Bump to next index */
- dbgPtr->bufTableIdx = (dbgPtr->bufTableIdx + 1L) %
- dbgPtr->bufTableSize;
-
- HLock(dbgPtr->bufData);/* Lock it down for output */
-
- /* Set switch code pointer */
- s = &(*dbgPtr->bufData)[(*dbgPtr->bufTable)
- [dbgPtr->bufTableIdx]];
-
- f = s + 2L; /* Set format string address */
-
- switch((unsigned char)(*s)){/* Process input command*/
-
- case accDbgPrint:/* Do LSC debugging line */
- DoDbgPrintSetUp(f); break;
-
- case accDbgDump:/* Do debugging dump */
- DoPrintDump(((long *)(f + sizeof(long))),
- *((long *)(f)));
-
- }
-
- dbgPtr = *dbgHdl; /* Reset debugger pointer */
-
- /* Check if it's finished */
- if (dbgPtr->bufTableIdx == dbgPtr->bufNextIdx) {
-
- if (!active) /* Check if not active */
- dce->dCtlFlags &= ~dNeedTime;/* Turn it off */
-
- else /* Restore delay timer */
- dce->dCtlDelay = 15;
-
- }
-
- HUnlock(dbgPtr->bufData);/* OK, let's unlock it now */
-
- }
-
- }
-
- }
-
- DoKey(c,code,modifiers)
-
- char c; /* Input character */
- char code; /* Input code */
- short modifiers; /* Input modifiers */
-
- {
-
- register short i,j; /* Working indexes */
- register short adjustIt = TRUE;/* Working adjust cursor view*/
- register short item = 0; /* Working item # */
- char cmdChar[2]; /* Working command character */
- register ControlHandle ctrlHdl;/* Working control handle */
- static short cnt = 0; /* Debugging counter */
-
- if (active) { /* Check if it's activated */
-
- if (modifiers & cmdKey) {/* Check if key command */
-
- switch(c) { /* Process key command */
-
- case 'd': /* "Debugging" command */
- case 'D':
-
- break; /* Break early, skip debugging */
-
- c = 0; /* Reset it to bypass remainder */
-
- /* Output debugging stuff */
- for(i = 0; i < 30; i++) {
- /*DbgPrint(dbgHdl,"Debugging - %d,%d, %s\n",
- i,cnt++,"Alex Colwell");*/
- DbgBufPrint(dbgHdl,"Debugging - %d,%d, %s, %d\n",
- i,cnt++,"Alex Colwell",cnt++);
- }
-
- break;
-
- case 'c': /* "Copy" command */
- case 'C':
- DoCopy(); c = 0; break;
-
- case 'k': /* "Clear" command */
- case 'K':
- DoClear(); c = 0;
-
- }
-
- if (c) { /* Check if should continue */
-
- if (menu) { /* Check if got our menu handle */
-
- /* Search for matching item */
- for(i = 1, j = CountMItems(menu); i <= j; i++) {
-
- /* Get this item's command */
- GetItemCmd(menu,i,cmdChar);
-
- if (cmdChar[1] == '?')/* Check if '?' char*/
- cmdChar[1] = '/';/* Translate lower case*/
-
- /* Check if this is it */
- if (!IUMagIDString(&c,&cmdChar[1],1,1)) {
- item = i;/* Yup, save item # */
- i += j;/* Break-out of loop */
- }
-
- }
-
- if (item){ /* Check if got our guy */
-
- HiliteMenu(menuID);/* OK, let's highlite it*/
-
- DoMenu(item);/* Let's do it */
-
- HiliteMenu(0);/* Unhighlite the menu */
-
- }
-
- else /* Opps, wrong menu */
- SysBeep(1);/* Let the user know about it*/
-
- }
-
- else /* Opps, no menu handle */
- SysBeep(1); /* Let the user know about it */
-
- }
-
- }
-
- else if (peHdl) { /* Check if got the text */
-
- if (sysEnv.keyBoardType == envAExtendKbd ||
- sysEnv.keyBoardType == envStandADBKbd) {
-
- /* Check if want scroll horz bar*/
- if (modifiers & optionKey)
- ctrlHdl = hScrollBar;/* Set horz scroll bar */
-
- else /* Nope, use vert scroll bar */
- ctrlHdl = vScrollBar;
-
- switch(code) { /* Check if F1-F4 keys */
-
- case 0x63: /* F3 "Copy" key */
- DoCopy(); break;
-
- case 0x73: /* Home key */
-
- if (ctrlHdl) {/* Check if has scroll bar*/
-
- /* Check if can scroll now */
- if (i = GetCtlValue(ctrlHdl)) {
-
- /* Reset clippings for scroll bar*/
- ClipRect(&wp->portRect);
-
- /* Reset the current line value */
- SetCtlValue(ctrlHdl,0);
-
- /* Restore clippings */
- DoRestoreClippings();
-
- /* OK, let's scroll it now! */
- if (ctrlHdl == vScrollBar)
- PEScroll(0,(long)(i),peHdl);
- else
- PEScroll(i,0L,peHdl);
-
- }
-
- }
-
- adjustIt = FALSE;/* Don't adjust view */
-
- break;
-
- case 0x77: /* End key */
-
- if (ctrlHdl) {/* Check if has scroll bar*/
-
- /* Check if can scroll now */
- if ((i = GetCtlValue(ctrlHdl)) !=
- (j = GetCtlMax(ctrlHdl))) {
-
- /* Reset clippings for scroll bar*/
- ClipRect(&wp->portRect);
-
- /* Reset the current line value */
- SetCtlValue(ctrlHdl,j);
-
- /* Restore clippings */
- DoRestoreClippings();
-
- /* OK, let's scroll it now! */
- if (ctrlHdl == vScrollBar)
- PEScroll(0,(long)(i - j),peHdl);
- else
- PEScroll(i - j,0L,peHdl);
-
- }
-
- }
-
- adjustIt = FALSE;/* Don't adjust view */
-
- break;
-
- case 0x74: /* Page up key */
-
- if (ctrlHdl) {/* Check if has scroll bar*/
-
- /* Scroll text upward */
- DoTextScroll(ctrlHdl,inPageUp);
-
- }
-
- adjustIt = FALSE;/* Don't adjust view */
-
- break;
-
- case 0x79: /* Page down key */
-
- if (ctrlHdl) {/* Check if has scroll bar*/
-
- /* Scroll text downward */
- DoTextScroll(ctrlHdl,inPageDown);
-
- }
-
- adjustIt = FALSE;/* Don't adjust view */
-
- break;
-
- }
-
- }
-
- if (adjustIt) /* Check if should adjust it */
- DoAdjustScrollBar();/* Adjust the scroll bar */
-
- }
-
- }
-
- }
-
- DoMenu(item)
-
- short item; /* Item code */
-
- {
-
- switch(item) { /* Process menu command */
-
- case Info: /* On-line information */
- DoInfo(); break;
-
- case StartOutput: /* Start/Stop output display */
- DoStartStopOutput(); break;
-
- case Quit: /* Quit from the DA */
- DoQuit(); break;
-
- }
-
- }
-
- DoContent(p,modifiers)
-
- Point p; /* Mouse down point */
- short modifiers; /* Mouse's modifiers */
-
- {
-
- long i; /* Working index */
- register short selectIt = FALSE;/* Working selection flag */
- Point pt; /* Working point */
-
- pt = p; /* Convert to local coordinates */
- GlobalToLocal(&pt);
-
- if (!DoScrollBar(pt)) /* Check if within scroll bar */
- DoTextClick(pt,modifiers);/* Do text clicking */
-
- }
-
- DoQuit()
-
- {
-
- SysBeep(1); /* Beep the user now! */
-
- CloseDriver(dce->dCtlRefNum);/* OK, let's close DA */
-
- }
-
- DoCopy()
-
- {
-
- register long len; /* Working text length */
-
- if (active) { /* Check if it's activated */
-
- if (peHdl) { /* Check if have edit handle */
- /* Check if there any selection */
- if (len = (*peHdl)->selEnd - (*peHdl)->selStart) {
-
- ZeroScrap(); /* Reset the scrap file */
-
- HLock((*peHdl)->hText);/* Lock the text down */
-
- /* Transfer to clipboard */
- PutScrap(len,'TEXT',*(*peHdl)->hText +
- (*peHdl)->selStart);
-
- HUnlock((*peHdl)->hText);/* OK, safe to unlock it*/
-
- }
-
- }
-
- }
-
- }
-
- DoClear()
-
- {
-
- register Handle txtHdl; /* Working text handle */
- Rect wRect; /* Working rect area */
-
- if (peHdl) { /* Check if have edit handle */
-
- if (txtHdl = NewHandle(0L)) {/* Check if got new handle */
-
- ClipRect(&wp->portRect);/* Reset clipping for a moment*/
-
- if (hScrollBar) { /* Check if have scroll bar */
-
- /* Reset scroll bar values */
- (*hScrollBar)->contrlMax = 0;
- SetCtlValue(hScrollBar,0);
-
- }
-
- if (vScrollBar) { /* Check if have scroll bar */
-
- /* Reset scroll bar values */
- (*vScrollBar)->contrlMax = 0;
- SetCtlValue(vScrollBar,0);
-
- }
-
- DoRestoreClippings();/* Restore text view clippings */
-
- DisposHandle((*peHdl)->hText);/* Release old text */
-
- (*peHdl)->hText = NIL;/* Reset it to zip! */
-
- PESetHText(txtHdl,peHdl);/* Set new text handle */
-
- wRect = wp->portRect;/* Clear the display */
- wRect.right -= 15; wRect.bottom -= 15;
- InvalRect(&wp->portRect);
-
- }
-
- }
-
- }
-
- DoInfo()
-
- {
-
- register DialogPtr dPtr; /* Working dialog pointer */
- short dItem; /* Working dialogue item */
- register short next = TRUE;/* Working next event flag */
-
- if (dbgHdl) { /* Check if got debugger ref hdl*/
-
- (*dbgHdl)->daRefNbr = 0;/* Clear debugger ref handle */
- ChangedResource(dbgHdl);
- WriteResource(dbgHdl);
-
- }
-
- DoDeActivateScrollBars(); /* Deactivate the scroll bars */
-
- DoDlgCenter('DLOG',infoID); /* Center the dialog now */
-
- /* Check if open dialog */
- if (dPtr = GetNewDialog(GetResourceID(infoID),NIL,-1L)) {
-
- InitCursor(); /* Restore to arrow cursor */
-
- cursorMode = FALSE; /* Reset cursor mode */
-
- SetPort(dPtr); /* Set to my window port */
-
- while(next) { /* Process next event */
-
- ModalDialog(NIL,&dItem);/* Get modal event */
-
- if (dItem == OK) /* Check if time to quit */
- next = FALSE; /* Let's break-out ! */
-
- }
-
- SetPort(wp); /* Restore DA's window port */
-
- DisposDialog(dPtr); /* Kill dialogue window */
-
- }
-
- DoActivateScrollBars(); /* Activate the scroll bars */
-
- if (dbgHdl) { /* Check if got debugger ref hdl*/
-
- if (outputEnable) { /* Check if display is enabled */
-
- /* Restore debugger ref handle */
- (*dbgHdl)->daRefNbr = dce->dCtlRefNum;
- ChangedResource(dbgHdl);
- WriteResource(dbgHdl);
-
- }
-
- }
-
- }
-
- DoStartStopOutput()
-
- {
-
- Str255 wStr; /* Working item string */
-
- if (dbgHdl) { /* Check if has debugger resource*/
-
- if (outputEnable) { /* Check if want to turn it off*/
-
- outputEnable = FALSE;/* Disable output display */
-
- (*dbgHdl)->daRefNbr = 0;/* Disable output processing*/
-
- /* Get item string to reset */
- GetIndString(wStr,GetResourceID(strID),itmStartOutput);
-
- }
-
- else { /* Nope, start-up output processing*/
-
- outputEnable = TRUE;/* Enable output display */
-
- /* Enable output processing */
- (*dbgHdl)->daRefNbr = dce->dCtlRefNum;
-
- /* Get item string to reset */
- GetIndString(wStr,GetResourceID(strID),itmStopOutput);
-
- }
-
- SetItem(menu,StartOutput,wStr);/* Reset the item string */
-
- }
-
- }
-
- DoError(errMsg)
-
- ERROR errMsg; /* Error message */
-
- {
-
- Str255 wStr; /* Working string */
-
- if (dbgHdl) { /* Check if got debugger ref hdl*/
-
- (*dbgHdl)->daRefNbr = 0;/* Clear debugger ref handle */
- ChangedResource(dbgHdl);
- WriteResource(dbgHdl);
-
- }
-
- /* Get error message */
- GetIndString(wStr,GetResourceID(errID),errMsg);
-
- ParamText(wStr,"","",""); /* Setup parameter text messages*/
-
- DoDlgCenter('ALRT',errorID);/* Center the alert dialog */
-
- DoDeActivateScrollBars(); /* Deactivate the scroll bars */
-
- CautionAlert(GetResourceID(errorID),NIL);/* Inform user now */
-
- DoActivateScrollBars(); /* Activate the scroll bars */
-
- if (dbgHdl) { /* Check if got debugger ref hdl*/
-
- if (outputEnable) { /* Check if display is enabled */
-
- /* Restore debugger ref handle */
- (*dbgHdl)->daRefNbr = dce->dCtlRefNum;
- ChangedResource(dbgHdl);
- WriteResource(dbgHdl);
-
- }
-
- }
-
- }
-
- DoTextClick(pt,modifiers)
-
- Point pt; /* Mouse down point */
- short modifiers; /* Modifiers selection */
-
- {
-
- register short extendIt = FALSE;/* Working extend selection*/
-
- if (peHdl) { /* Check if got the text */
-
- if ((*peHdl)->peLength > 0) {/* Check if there any text */
-
- if (modifiers & shiftKey)/* Check if want to extend it*/
- extendIt = TRUE;/* Extend the selection then */
-
- PEClick(pt,extendIt,peHdl);/* Do clicking stuff */
-
- }
-
- }
-
- }
-
- DoScrollBar(pt)
-
- Point pt; /* Mouse down point */
-
- {
-
- register short partCtrl; /* Working control part */
- ControlHandle ctrlHdl; /* Working control handle */
-
- /* Check if got a control part */
- if (partCtrl = FindControl(pt,wp,&ctrlHdl)) {
-
- ClipRect(&wp->portRect);/* Set clippings for scrolling */
-
- if (partCtrl == inThumb) {/* Check if using thumb */
-
- /* Save current control's value */
- SetCRefCon(ctrlHdl,GetCtlValue(ctrlHdl));
-
- ClipRect(&wp->portRect);/* Reset clippings for a moment*/
-
- TrackControl(ctrlHdl,pt,NIL);/* Let's track by thumb*/
-
- DoTextScroll(ctrlHdl,inThumb);/* OK, let's scroll */
-
- DoRestoreClippings();/* Restore text view clippings */
-
- }
-
- else { /* Nope, other types of scrolling*/
-
- ClipRect(&wp->portRect);/* Reset clippings for a moment*/
-
- /* OK, lets scroll it now */
- TrackControl(ctrlHdl,pt,DoTextScroll);
-
- DoRestoreClippings();/* Restore text view clippings */
-
- }
-
- }
-
- return(partCtrl); /* Return part control */
-
- }
-
- pascal void DoTextScroll(ctrlHdl,partCtrl)
-
- ControlHandle ctrlHdl; /* Control scroll handle */
- short partCtrl; /* Control's part */
-
- {
-
- register short delta; /* Working delta scroll */
- register short value; /* Working current value */
- register short maxValue; /* Working maximum value */
- register short viewLines; /* Working view lines */
- short dh = 0; /* Working delta horizonal */
- long dv = 0; /* Working delta vertical */
- PEPtr pePtr; /* Working edit pointer */
-
- SetUpA4(); /* Setup register A4 */
-
- delta = GetCtlValue(ctrlHdl);/* Get current value */
-
- maxValue = GetCtlMax(ctrlHdl);/* Get maximum value */
-
- switch(partCtrl) { /* Handle request: */
-
- case 0: /* "Nothing" */
- return;
-
- case inUpButton:
-
- value = max(0,delta - 1);/* Set new value position */
-
- break;
-
- case inDownButton:
-
- value = min(maxValue,delta + 1);/* Set new value position*/
-
- break;
-
- case inPageUp: /* "Page Up" */
- case inPageDown: /* "Page Down" */
-
- if (ctrlHdl == vScrollBar) {/* Check if vertical */
-
- pePtr = *peHdl; /* Set edit text pointer */
-
- /* Set # of visible lines by half*/
- viewLines = (pePtr->viewRect.bottom -
- pePtr->viewRect.top) / pePtr->lineHeight;
-
- if (partCtrl == inPageUp)/* Check if page up region */
- value = max(0,delta - viewLines);
-
- else /* Nope, page down region */
- value = min(maxValue,delta + viewLines);
-
- }
-
- else { /* Check if horizontal */
-
- if (partCtrl == inPageUp)/* Check if page up region*/
- value = max(0,delta - 10);/* Set new position */
-
- else /* Nope, page down region */
- value = min(maxValue,delta + 10);
-
- }
-
- break;
-
- case inThumb: /* "Thumb" */
-
- delta = GetCRefCon(ctrlHdl);/* Get starting value */
-
- value = GetCtlValue(ctrlHdl);/* Get new value position*/
-
- }
-
- SetCtlValue(ctrlHdl,value); /* Reset the value */
-
- if (hScrollBar == ctrlHdl) /* Check if horzontal */
- dh = delta - value; /* Set horizontal offset */
-
- else
- dv = delta - value; /* Set vertical offset */
-
- DoRestoreClippings(); /* Restore text view clippings */
-
- if (dh || dv) /* Check if should scroll it */
- PEScroll(dh * CharWidth(' '),dv,peHdl);/* Scroll it now */
-
- ClipRect(&wp->portRect); /* Reset clippings for a moment */
-
- RestoreA4(); /* Restore register A4 */
-
- }
-
- pascal void DoClickScroll(peHdl)
-
- register PEHandle peHdl; /* Edit data handle */
-
- {
-
- register Rect viewRect; /* Working view rect area */
- Point pt; /* Working mouse point position */
-
- viewRect = (*peHdl)->viewRect;/* Set view rect area */
-
- GetMouse(&pt); /* Get current mouse position */
-
- if (pt.v < viewRect.top) /* Check if going upward */
- DoTextScroll(vScrollBar,inUpButton);
-
- else if (pt.v > viewRect.bottom)/* Check if going downward */
- DoTextScroll(vScrollBar,inDownButton);
-
- else if (pt.h < viewRect.left)/* Check if going leftward */
- DoTextScroll(hScrollBar,inUpButton);
-
- else if (pt.h > viewRect.right)/* Check if going rightward */
- DoTextScroll(hScrollBar,inDownButton);
-
- }
-
- pascal void DoHighLite(hilite,pePtr)
-
- Rect *hilite; /* Highlite rect area */
- register PEPtr pePtr; /* Edit text pointer */
-
- {
-
- HiliteMode &= 0x7f; /* Set highliting bit */
-
- InvertRect(hilite); /* Invert rect area */
-
- }
-
- DoNewLineToReturn(s)
-
- char *s; /* Input string pointer */
-
- {
- while(*s) { /* Convert NEW-LINEs to RETURNs */
- if (*s == '\n') /* Check if this is NEW-LINE char*/
- *s = '\r'; /* Convert to RETURN character */
- s += 1; /* Bump to next character */
- }
- }
-
- DoPrintLine(format,args)
-
- char *format; /* Format string pointer */
- va_list args; /* Argument's list */
-
- {
-
- vsprintf(PrintOutputBuf,format,&args);/* Format str to buf */
-
- DoNewLineToReturn(PrintOutputBuf);/* Convert NEW-LINE to RETURN*/
-
- /* Output string to display */
- PEInsert(PrintOutputBuf,DbgStrLen(PrintOutputBuf),peHdl);
-
- DoAdjustScrollBar(); /* Adjust the scroll bar */
-
- }
-
- DoDbgPrintSetUp(fmt)
-
- char *fmt; /* Input format pointer */
-
- {
-
-
- register short fLen; /* Working format string length */
- register char *stack; /* Working fake stack pointer */
-
- fLen = DbgStrLen(fmt) + 1; /* Set string length */
-
- if (fLen & 0x1) /* Check if it's even # of chars*/
- fLen += 1; /* Align it to even addresss */
-
- stack = fmt + fLen; /* Set format string address */
- *((long *)(stack)) = ((long)(fmt));
-
- DoDbgPrint(stack); /* OK, let's really do it */
-
- }
-
- DoDbgPrint(args)
-
- long *args; /* Input argument's list */
-
- {
-
- DoSetupView(); /* Setup the view display */
-
- DoAdjustView(); /* Adjust the view */
-
- vsprintf(PrintOutputBuf,*args,args + 1L);/* Format str to buffer*/
-
- DoNewLineToReturn(PrintOutputBuf);/* Convert NEW-LINE to RETURN*/
-
- /* Output string to display */
- PEInsert(PrintOutputBuf,DbgStrLen(PrintOutputBuf),peHdl);
-
- DoAdjustScrollBar(); /* Adjust the scroll bar */
-
- }
-
- DoPrintDump(ptr,size)
-
- char *ptr; /* Print buffer pointer */
- long size; /* Print buffer length */
-
- {
-
- register long i,j,k,m,n; /* Working indexes */
- register char *tptr; /* Working temporary pointer */
- Str255 buffer; /* Working string buffer */
- Str255 tbuffer; /* Working temporary buffer */
-
- DoSetupView(); /* Setup the view display */
-
- DoAdjustView(); /* Adjust the view */
-
- /* Output # of bytes dumped */
- DoPrintLine("\nNumber of bytes - %ld\n",size);
- DoPrintLine("Cnt Address %s %s\n",
- "Hex Values—————————————————————————",
- "ASCII Values————");
-
- for(i = 0L; i < size; i += 16L) {/* Transfer all the data */
-
- n = 14L; /* Set init buffer index */
-
- for(j = 0L; j < sizeof(buffer); j++)/* Clear buffer string */
- buffer[j] = ' '; /* Pad it with spaces */
-
- sprintf(buffer,"%04ld %08lx ",i,tptr = ptr);/* Set init hdr*/
-
- j = i; k = m = 0L; /* Init indexes */
-
- while(j < size && m < 16L) {/* Output hex parts */
-
- m += 1L; /* Bump # of characters */
-
- if (k++ == 3L) { /* Check if time to pad space */
-
- sprintf(tbuffer,"%04x ",*tptr++);/* Get char hex value*/
-
- /* Add it to output buffer */
- BlockMove(&tbuffer[2],&buffer[n],
- DbgStrLen((char *)(&tbuffer[2])) + 1);
-
- k = 0L; /* Reset index */
-
- n += 1L; /* Bump one extra */
-
- }
-
- else {
-
- sprintf(tbuffer,"%04x",*tptr++);/* Get char hex value*/
-
- /* Add it to output buffer */
- BlockMove(&tbuffer[2],&buffer[n],
- DbgStrLen((char *)(&tbuffer[2])) + 1);
-
- }
-
- j += 1L; /* Bump to next character */
-
- n += 2L; /* Bump for two hex characters */
-
- }
-
- buffer[n] = ' '; /* Remove the end-of-string */
-
- n = 50L; /* Reset the character index */
-
- j = i; m = 0L; /* Init indexes */
-
- while(j < size && m < 16L) {/* Output hex parts */
-
- j += 1L; /* Bump to next character */
-
- m += 1L; /* Bump # of characters */
-
- if (isprint(*ptr)) /* Check if printable */
- sprintf(&buffer[n],"%c",*ptr++);/* Output char */
-
- else { /* It's not printable */
-
- BlockMove(".",&buffer[n],2L);/* Show period only */
-
- ptr += 1L; /* Bump to next character */
-
- }
-
- n += 1L; /* Bump for one character */
-
- }
-
- /* Add RETURN character */
- BlockMove("\r",&buffer[DbgStrLen((char *)(buffer))],2L);
-
- DoPrintLine("%s",buffer); /* Output the string */
-
- }
-
- }
-
- DoRestoreClippings()
-
- {
-
- Rect wRect; /* Working rect area */
-
- if (peHdl) { /* Check if it's valid */
-
- wRect = (*peHdl)->viewRect;/* Restore clipping */
- ClipRect(&wRect);
-
- }
-
- }
-
- DoAdjustScrollBar()
-
- {
-
- register short viewHeight; /* Working view height */
- register short hiddenLines;/* Working # of hidden lines */
- register PEPtr pePtr; /* Working edit pointer */
-
- if (peHdl) { /* Check if have edit handle */
-
- pePtr = *peHdl; /* Set edit pointer */
-
- if (pePtr->peLength) { /* Check if there any text */
-
- ClipRect(&wp->portRect);/* Reset clippings for moment*/
-
- if (hScrollBar) { /* Check if there a horz scroll */
-
- if (!GetCtlMax(hScrollBar))/* Check if not init */
- SetCtlMax(hScrollBar,maxColumns);/* Reset to max*/
-
- }
-
- if (vScrollBar) { /* Check if there a vert scroll */
-
- /* Set view height display */
- viewHeight = abs(pePtr->viewRect.bottom -
- pePtr->viewRect.top);
-
- /* Check if need to enable it */
- if (pePtr->nLines * pePtr->lineHeight > viewHeight) {
-
- /* Set # of hidden lines */
- hiddenLines = max(0,pePtr->nLines - viewHeight /
- pePtr->lineHeight);
-
- /* Check if the hidden lines changed*/
- if (GetCtlMax(vScrollBar) != hiddenLines) {
-
- /* Update the maximum # of lines*/
- (*vScrollBar)->contrlMax = hiddenLines - 1;
-
- /* Adjust thumb position */
- SetCtlValue(vScrollBar,
- min((short)pePtr->viewOrgV,hiddenLines - 1));
-
- DoAdjustView();/* Adjust the view */
-
- }
-
- }
-
- else { /* Nope, disable the scroll bar */
-
- /* Check if it's enabled */
- if (GetCtlMax(vScrollBar)) {
-
- (*vScrollBar)->contrlMax = 0;/* Reset it*/
- SetCtlValue(vScrollBar,0);
-
- }
-
- }
-
- }
-
- }
-
- else { /* Reset the scroll bars */
-
- if (hScrollBar) { /* Check if there a horz scroll */
-
- if (GetCtlMax(hScrollBar)) {/* Check if enabled */
-
- (*hScrollBar)->contrlMax = 0;/* Reset it */
- SetCtlValue(hScrollBar,0);
-
- }
-
- }
-
- if (vScrollBar) { /* Check if there a vert scroll */
-
- if (GetCtlMax(vScrollBar)) {/* Check if enabled */
-
- (*vScrollBar)->contrlMax = 0;/* Reset it */
- SetCtlValue(vScrollBar,0);
-
- }
-
- }
-
- }
-
- DoRestoreClippings(); /* Restore text view clippings */
-
- }
-
- }
-
- DoSetupView()
-
- {
-
- register PEPtr pePtr; /* Working edit data pointer */
-
- if (peHdl) { /* Check if have edit handle */
-
- pePtr = *peHdl; /* Set edit pointer */
-
- /* Check if have selected text */
- if (pePtr->selStart != pePtr->selEnd)
- PESetSelect(pePtr->peLength,pePtr->peLength,peHdl);
-
- /* Check if not at end-of-text */
- else if (pePtr->selStart != pePtr->peLength)
- PESetSelect(pePtr->peLength,pePtr->peLength,peHdl);
-
- }
-
- }
-
- DoAdjustView()
-
- {
-
- register PEPtr pePtr; /* Working edit data pointer */
- long delta; /* Working delta line offset */
- long currentLine;/* Working current line selection*/
- register long selectLine;/* Working line selection */
- register long viewLines; /* Working view lines */
- long hViewLines; /* Working half view lines */
- register long viewOrgV; /* Working origin view offset */
- long saveSelStr; /* Working save selStart value */
- long saveSelEnd; /* Working save selEnd value */
- register long status = TRUE;/* Working adjust view indicator*/
- short adjust = FALSE;/* Working vertical adjustment*/
-
- if (peHdl) { /* Check if have edit handle */
-
- DoRestoreClippings(); /* Restore text view clippings */
-
- pePtr = *peHdl; /* Set edit text pointer */
-
- if (optHdl) { /* Check if option handle valid */
-
- if ((*optHdl)->maxTextSize) {/* Check if maxing input data*/
-
- /* Set current line to chop */
- currentLine = pePtr->peLength - (*optHdl)->maxTextSize;
-
- if (currentLine > 0) {/* Check if time to chop */
-
- PECloseGap(peHdl);/* Close the gap first */
-
- saveSelStr = pePtr->selStart;/* Save start selection*/
-
- saveSelEnd = pePtr->selEnd;/* Save end selection */
-
- /* Reset selection */
- PESetSelect(0L,currentLine = PEEol(currentLine,
- peHdl) + 1L,peHdl);
-
- PEDelete(peHdl); /* OK, let's delete it */
-
- /* Restore it */
- PESetSelect(saveSelStr - currentLine,
- saveSelEnd - currentLine,peHdl);
-
- }
-
- }
-
- }
-
- pePtr = *peHdl; /* Set edit text pointer */
-
- viewOrgV = pePtr->viewOrgV;/* Set view origin offset */
-
- /* Set # of visible lines */
- viewLines = abs(pePtr->viewRect.bottom - pePtr->viewRect.top) /
- pePtr->lineHeight;
-
- hViewLines = viewLines / 2;/* Half of the view lines */
-
- /* Set selected line # */
- selectLine = currentLine = PELineNum(pePtr->selEnd,peHdl);
-
- pePtr = *peHdl; /* Reset edit text pointer */
-
- /* Check if within view */
- if (selectLine >= viewOrgV && selectLine < viewOrgV + viewLines)
- status = FALSE;
-
- if (status) { /* Check if should adjust view */
-
- adjust = TRUE; /* Set adjust the vertical offset*/
-
- selectLine -= viewOrgV; /* Adjust select line # */
-
- if (selectLine == viewLines)/* Check if just off the page*/
- selectLine -= viewLines - 1;/* Adjust by one line */
-
- /* Check if close to the bottom */
- else if (delta = (pePtr->nLines - currentLine -
- 1 - hViewLines) < 0)
- selectLine += delta - viewLines;/* Adjust to bottom of file*/
-
- else if (selectLine != -1) /* Check if completely off */
- selectLine -= hViewLines;/* Center the page */
-
- selectLine += viewOrgV; /* Adjust to physical offset */
-
- /* Scroll to cursor */
- PEScrollTo(pePtr->viewOrgH,selectLine,peHdl);
-
- }
-
- }
-
- }
-
- DoResizeScrollBar()
-
- {
-
- Rect wRect; /* Working window rect area */
-
- if (peHdl) { /* Check if have edit handle */
-
- wRect.left = wp->portRect.left;
- wRect.top = wp->portRect.top + 5;
- wRect.right = wp->portRect.right - 15;
- wRect.bottom = wp->portRect.bottom - 15;
-
- (*peHdl)->viewRect = wRect;
-
- }
-
- if (hScrollBar) { /* Check if have scroll bar */
-
- /* Compute scroll bar rect area */
- wRect.left = wp->portRect.left - 1;
- wRect.top = wp->portRect.bottom - 15;
- wRect.right = wp->portRect.right - 14;
- wRect.bottom = wp->portRect.bottom + 1;
-
- /* Set new control rect area */
- (*hScrollBar)->contrlRect = wRect;
-
- }
-
- if (vScrollBar) { /* Check if have scroll bar */
-
- /* Compute scroll bar rect area */
- wRect.left = wp->portRect.right - 15;
- wRect.top = wp->portRect.top - 1;
- wRect.right = wp->portRect.right + 1;
- wRect.bottom = wp->portRect.bottom - 14;
-
- /* Set new control rect area */
- (*vScrollBar)->contrlRect = wRect;
-
- }
-
- }
-
- DialogTHndl DoDlgCenter(type,id)
-
- long type; /* Resource type id */
- short id; /* Id # */
-
- {
-
- register DialogTHndl dhdl; /* Working dialog template handle*/
- register DialogTPtr dptr; /* Working dialog template pointer*/
- WindowPtr wPtr; /* Working window pointer */
- register short swidth; /* Working 1/2 horz screen width*/
- register short width; /* Working 1/2 horz dialog width*/
-
- /* Check if got the dialog handle*/
- if (dhdl = ((DialogTHndl)GetResource(type,GetResourceID(id)))) {
-
- GetWMgrPort(&wPtr); /* Get window manager pointer */
-
- dptr = *dhdl; /* Set dialog template pointer */
-
- /* Set 1/2 screen width */
- swidth = abs(wPtr->portRect.right - wPtr->portRect.left) / 2;
-
- /* Set 1/2 dialog width */
- width = abs(dptr->boundsRect.right - dptr->boundsRect.left) / 2;
-
- /* Center the dialog */
- dptr->boundsRect.left = swidth - width;
- dptr->boundsRect.right = swidth + width;
-
- }
-
- return(dhdl); /* Return dialog handle */
-
- }
-
- DoItemIdx(item,menu)
-
- register unsigned char *item; /* Item string to look up */
- register MenuHandle menu; /* Menu handle */
-
- {
-
- register short i,j; /* Working index */
- register unsigned short len = *item++;/* Working item length*/
- Str255 wStr; /* Working string */
-
- /* Look for matching item */
- for(i = 1, j = CountMItems(menu); i <= j; i++) {
-
- GetItem(menu,i,&wStr); /* Working string */
-
- if (!IUMagString(item,&wStr[1],len,len))/* Check if matches*/
- return(i); /* Found matching string */
-
- }
-
- return(1); /* Opps, didn't find it */
-
- }
-
- GetResourceID(n) { return(0xC000 + ((~(dce->dCtlRefNum))<<5) + n); }
-
-